package main.java.com.silence.controller;

import com.silence.pojo.Bill;
import com.silence.vo.Pager;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author: silence
 * Date: 17-5-29
 */
@Controller
public class TestController {

    /**
     * 解决复杂数据绑定
     *
     *  Date日期类型
     */
    @InitBinder
    protected void initBinder(HttpServletRequest request,
                              ServletRequestDataBinder binder) throws Exception {
        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor dateEditor = new CustomDateEditor(fmt, true);
        binder.registerCustomEditor(Date.class, dateEditor);
    }


    @RequestMapping(value = "/demo2")
    public String test(RedirectAttributes attributes) {

        attributes.addAttribute("msg", "this is massage");

        return "redirect:/showMsg";
    }

    @RequestMapping(value = "/testDate")
    public void testDate(Date date) {
        System.out.println(date);
    }


}
